﻿using Microsoft.AspNetCore.Hosting;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading;
using System.Threading.Tasks;

namespace WeChatApp.Repositories
{
    public class FileRepository:BaseRepository
    {
        public FileRepository()
        {

        }
        private readonly IHostingEnvironment _hostingEnvironment;
        public FileRepository(IHostingEnvironment hostingEnvironment)
        {
            _hostingEnvironment = hostingEnvironment;
        }
        public MemoryStream MakeFiletxt(string fileName)
        {
            string FilePath = _hostingEnvironment.WebRootPath;
            string contentRootPath = _hostingEnvironment.ContentRootPath;
            FilePath += "\\tempFile\\" + fileName;
            FileStream fileStream = new FileStream(FilePath, FileMode.Open, FileAccess.Read, FileShare.Read);
            byte[] bytes = new byte[fileStream.Length];
            fileStream.Read(bytes, 0, bytes.Length);
            fileStream.Close();
            var stream = new MemoryStream(bytes);
            stream.Position = 0;
            return stream;
        }
    }
}
